package top.gbyun.engine.processor;

import akka.actor.ActorContext;
import top.gbyun.core.ActorSystemContext;
import top.gbyun.core.enmus.ComponentLifecycleState;

/**
 * @author gengbin
 * @date 2024-12-25-14:47
 */
public abstract class ComponentMsgProcessor extends AbstractComponentProcessor{
    protected final String flowId;

    protected ComponentLifecycleState state;


    protected ComponentMsgProcessor(ActorSystemContext systemContext, String flowId) {
        super(systemContext);
        this.flowId = flowId;
    }

    public abstract void start(ActorContext context) throws Exception;

    public abstract void stop(ActorContext context) throws Exception;

    public abstract void onCreated(ActorContext context) throws Exception;

    public abstract void onUpdate(ActorContext context) throws Exception;

    public abstract void onActivate(ActorContext context) throws Exception;

    public abstract void onSuspend(ActorContext context) throws Exception;

    public abstract void onStop(ActorContext context) throws Exception;

    protected void restart(ActorContext context) throws Exception {
        stop(context);
        start(context);
    }

    /*protected void checkActive(EngineMsg msg) throws RuleNodeException {
        if (state != ComponentLifecycleState.ACTIVE) {
            log.debug("Component is not active. Current state [{}] for processor [{}] tenant [{}]", state, id, ruleId);
            RuleNodeException ruleNodeException = getInactiveException();
            if (msg != null) {
                msg.getCallback().onFailure(ruleNodeException);
            }
            throw ruleNodeException;
        }
    }*/
}
